<?php

class FormCheckOut extends CFormModel
{
	public $firstName = null;
	public $lastName = null;
	public $street1 = null;
	public $street2 = null;
	public $location = null;
	public $city = null;
	public $state = null;
	public $zipCode = null;
	public $payment = null;
	public $paypalemail = null;
	public $email = null;
	public $terms1  = null;
	public $terms2  = null;
	public $terms3  = null;
	public $phone  = null;
	public $note  = null;
	
	public function rules() {
		return array(
			array('firstName,lastName', 'required','message'=>"Please enter your {attribute}"),
			array('street1,email', 'required','message'=>"Please enter valid {attribute}"),
			array('paypalemail', 'required','message'=>"Please enter valid {attribute}","on"=>"payment"),
			array('location', 'checkLocation'),
			array('zipCode', 'length', 'max'=>10),
			array('paypalemail', 'email'),
			array('email', 'email'),
			array('terms1', 'term1'),
			array('terms2', 'term2'),
			array('terms3', 'term3'),

		);
	}
	public function term1($attribute, $params)
	{
		
		if ($this->terms1==null)
			$this->addError('terms1', "Please accept Terms & Conditions.");
	}
	public function term2($attribute, $params)
	{
		
		if ($this->terms2==null)
			$this->addError('terms2', "Please accept Terms & Conditions.");
	}
	public function term3($attribute, $params)
	{
		if ($this->terms3==null)
			$this->addError('terms3', "Please accept Terms & Conditions.");
	}
	public function attributeLabels()
	{
		return array(
			'firstName' => 'first name',
			'lastName' => 'last name',
			'street1' => 'street',
			'street2' => 'street',
			'location' => 'Location',
			'paypalemail' => 'PayPal email',
			'email' => 'email',
			'phone' => 'phone',
			'note' => 'note',
			'state' => 'state',
		);
	}
	public function checkLocation($attribute, $params)
	{
		
		if ($this->city==null || $this->zipCode==null || $this->state==null)
			$this->addError('location', "Please enter city, state, zipCode.");
	}
	public function checkFullName($attribute, $params)
	{
		$this->fullname = $this->firstName . " " .$this->lastName;
		if (trim($this->fullname)=="")
			$this->addError('fullname', "Please enter your full name.");
	}

}
